/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function TaxiTariff() {
    this.javaClass = "limousine.vo.TaxiTariff"; 
        
    this.taxiRateId = "";
    this.distination ="";
    this.taxiSize ="";
    this.oneWay ="";
    this.roundTrip ="";
    this.taxiTariffOrder ="";        
    this.createBy ="";
    this.createDate ="";
    this.updateBy ="";
    this.updateDate ="";
   
}
function openLookup() {
    var body = $d("_body");
    body.innerHTML = requestPage("lookup.main.jsp");

    var x = new Driver();

    x.tableId
}
function edit(id) {
    try {
        //alert("Rate Id["+ id +"]");
        formEntry();
        document.getElementById("fieldSetLabel").textContent="Taxi Tariff Edit";
        var o = service.findById(id);   
        $d("taxiRateId").value = o.taxiRateId;
        $d("distination").value = o.distination;
        $d("taxiSize").value = o.taxiSize;
        $d("oneWay").value = o.oneWay;
        $d("roundTrip").value = o.roundTrip;
        $d("taxiTariffOrder").value = o.taxiTariffOrder;        
        $d("createBy").value = o.createBy;
        $d("createDate").value = o.createDate;
        $d("updateBy").value = o.updateBy;
        $d("updateDate").value = o.updateDate;
        $d("bSave").setAttribute("onclick","save()");
    } catch(err) {
        alert("edit err:"+err);
    }
}

function switchProcess(type,msg,method){
    if(type == 0){//fail
        addSysMsg(0,msg);
    }else{
        addProcessing(msg);
        setTimeout(method,2500);        
    }    
}
function save() { 
    
    try {
        var o = new TaxiTariff();
        
        o.taxiRateId = $d("taxiRateId").value;
        o.distination = $d("distination").value;
        o.taxiSize = parseInt($d("taxiSize").value);
        o.oneWay = parseInt($d("oneWay").value);
        o.roundTrip = parseInt($d("roundTrip").value);
        o.taxiTariffOrder = parseInt($d("taxiTariffOrder").value);        
        o.createBy = $d("createBy").value;
        o.createDate = $d("createDate").value;
        o.updateBy = $d("updateBy").value;
        o.updateDate = $d("updateDate").value;

        if( verify() == true ) {
            addProcessing('Please wait...');
            var ret = service.update(o);
            if( ret == "true" ) {                
                switchProcess(1,"Save completed.","formSearch()");
            } else {
                switchProcess(0,"Save fail.","");                
            }
            //clearAllMsg();
        }
    } catch(err) {
        alert("save err:"+err);
    }
}
function remove(id) {
    try {
        addProcessing('Please wait...');
        service.remove(id);
        search(0);
        clearAllMsg();
    } catch(err) {
        alert("remove err:"+err);
    }
}
function search() {
    try {
        var ls = service.search(0, $d("tTableId").value);
        var jTable = new JTable();
        jTable.setTableId("driverTable");
        jTable.setColumns(["driverName", "driverType", "driverRate", "perType"]);
        jTable.setFields(["driverName","driverType","driverRate", "perType"]);
        jTable.setEditFunction("edit");
        jTable.setDeleteFunction("remove");
        jTable.setDataId("driverId");
        jTable.setCount(ls.size());
        jTable.setOffset(0);
        jTable.setDataPageSize(20);
        jTable.setPageLink("pagelink");
        jTable.setTableHeader();
        jTable.loadData(ls);
    } catch(err) {
        alert("search err:"+err);
    }
}
function search(offset) {
    
    try {               
        addProcessing('Please wait...');
        var ls = service.search(offset,$d("tTaxiRateId").value); 
        //alert("Taxi rate["+ $d("tTaxiRateId").value +"]");
        var jTable = new JTable();

        jTable.setTableId("tableData");        
        jTable.setColumns(["Taxi Rate Id", "Distination","Taxi Size","One Way", "Round Trip","Taxi Tariff Order", "Update By", "Update Date"]);
        jTable.setFields(["taxiRateId", "distination","taxiSize","oneWay", "roundTrip","taxiTariffOrder", "updateBy", "updateDate"]);
        jTable.setEditFunction("edit");
        jTable.setDeleteFunction("remove");
        jTable.setDataId("taxiRateId");
        jTable.setCount(ls.size());
        jTable.setOffset(offset);
        jTable.setDataPageSize(20);
        jTable.setPageLink("search");        
        jTable.setTableHeader();
        jTable.loadData(ls);        
        
    } catch(err) {
        alert("search err:"+err);        
    }
    clearAllMsg();
}
function insert() { 
    
    try {
        var o = new TaxiTariff();
                
        o.taxiRateId = $d("taxiRateId").value;
        o.distination = $d("distination").value;
        o.taxiSize = parseInt($d("taxiSize").value);
        o.oneWay = parseInt($d("oneWay").value);
        o.roundTrip = parseInt($d("roundTrip").value);
        o.taxiTariffOrder = parseInt($d("taxiTariffOrder").value);        
        o.createBy = $d("createBy").value;
        //o.createDate = $d("createDate").value;
        o.updateBy = $d("updateBy").value;
        //o.updateDate = $d("updateDate").value;
        
        //        var re = service.save(lookup);
        if( verify() == true ) {
            addProcessing('Please wait...');
            var ret = service.save(o);
            if( ret == "true" ) {            
                switchProcess(1,"Add completed.","formSearch()");
            } else {            
                switchProcess(0,"Add fail.","");
            }
        }
        //clearAllMsg();
    } catch(err) {
        alert("insert err:"+err);
    }
}
        
function setInsert() {    
    try {
        formEntry();
        var searchd = $d("taxiRateId").value;
        $d("actionForm").reset();
        //$d("taxiRateId").value = searchd;
        $d("taxiRateId").value = service.requestId();
        $d("bSave").setAttribute("onclick","insert()");
        
    } catch(err) {
        alert("setInsert err:"+err);
    }
}
         
function formEntry() {
    clearAllMsg();
    document.getElementById("fieldSetLabel").textContent="Taxi Tariff Add";
    try {
        $d("formSearch").style.visibility = "hidden";
        var formEntry = $d("formEntry");
        formEntry.style.visibility = "visible";
        var panel = $d("panel");
        formEntry.style.top = panel.style.top;
        formEntry.style.left = panel.style.left;
    } catch(err) {
        alert("formEntry err:"+err);
    }
}
function formSearch() {
    clearAllMsg();
    document.getElementById("fieldSetLabel").textContent="Taxi Tariff Search";    
    try {
        $d("formEntry").style.visibility = "hidden";
        var search = $d("formSearch");
        search.style.visibility = "visible";
        var panel = $d("panel");
        search.style.top = panel.style.top;
        search.style.left = panel.style.left;
    } catch(err) {
        alert("formSearch err:"+err);
    }
}
function verify() {
    //alert('Test in');
    try {
        var v = new Validation();
        v.addField("name='taxiRateId',label='Taxi Rate Id',min=1,max=21,type='string',require=true");
        v.addField("name='distination',label='Destination',min=2,max=50,type='string',require=true");
        v.addField("name='taxiSize',label='Taxi Size',min=0,max=20,type='int',require=true");
        v.addField("name='oneWay',label='One Way',min=0,max=3000,type='int',require=true");
        v.addField("name='roundTrip',label='Round Trip',min=2,max=3000,type='int',require=true");
        v.addField("name='taxiTariffOrder',label='Taxi Tariff Order',min=2,max=200,type='int',require=true");
   
        var str = v.execute();
        if ( str == "" ) {
            return true;
        } else {
            addSysMsg(0,str);
            return false;
        }
    } catch(err) {
        alert("verify err:"+err);
    }
}